package com.ruoyi.web.controller.common;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.EncryUtils;
import com.ruoyi.common.utils.RsaUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class VersionController {

    private String clientPubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmaWVnxCHvgd2mg52h314pP/iViCopX/aTXGSXYKPlEnsy6GpvIh0vrs2cVA2dshDhVI/EOncz/b3Ewd0cX90+qqJ0KzDFlbhw7OY740yBEVh5X/Z4oNmrxiF7QdjUq1qqvLqY1XRKY9yA+Gd/tHZafwbkqetm1oWcs2iq6PNTe2LJpixCqzjF+LhrerfTfLvcuek03h4Uxi+AM7eNtDO3D7OfXY2eB3tQZQ2snC17TDHe9UzIg9zPZU0Ot3TdaLruIhbLpfvmAY3FU+8gFf2Q3muWAtL10PNPjFPyd/BanPUiE73BaKOuMvPCVzCvPulbGHe1M+4wIvHoq+SBYIp3wIDAQAB";
    private String clientPriKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCZpZWfEIe+B3aaDnaHfXik/+JWIKilf9pNcZJdgo+USezLoam8iHS+uzZxUDZ2yEOFUj8Q6dzP9vcTB3Rxf3T6qonQrMMWVuHDs5jvjTIERWHlf9nig2avGIXtB2NSrWqq8upjVdEpj3ID4Z3+0dlp/BuSp62bWhZyzaKro81N7YsmmLEKrOMX4uGt6t9N8u9y56TTeHhTGL4Azt420M7cPs59djZ4He1BlDaycLXtMMd71TMiD3M9lTQ63dN1ouu4iFsul++YBjcVT7yAV/ZDea5YC0vXQ80+MU/J38Fqc9SITvcFoo64y88JXMK8+6VsYd7Uz7jAi8eir5IFginfAgMBAAECggEAZF/WVSn5Y92AT7hvGqiPbkt0U4vWYPg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Um6e5hOHquvX39GHsgLfgnVkrSMm+m0=";
    @PostMapping("/check")
    public String check(@RequestBody JSONObject object) throws Exception {
        String version = object.getString("version");
        System.out.println("version:"+version);
        System.out.println("desc:"+ EncryUtils.decryptByPrivateKey(version,clientPriKey));
        return EncryUtils.encryptByPublicKey(DateUtils.getDate(),serverPubKey);
    }
}
